// lib/components/ImagePreview.dart
import 'package:flutter/material.dart';
import 'package:photo_view/photo_view.dart';
import 'package:f_enjoy_plus/components/Header.dart';

class ImagePreview extends StatelessWidget {
  final String imageUrl;
  final String title;

  const ImagePreview({
    Key? key,
    required this.imageUrl,
    this.title = '图片预览',
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: Header(
        title: title,
        backgroundColor: Colors.black,
      ),
      body: Container(
        color: Colors.black,
        constraints: BoxConstraints.expand(),
        child: PhotoView(
          imageProvider: NetworkImage(imageUrl),
          minScale: PhotoViewComputedScale.contained,
          maxScale: PhotoViewComputedScale.covered * 2,
          initialScale: PhotoViewComputedScale.contained,
          backgroundDecoration: BoxDecoration(
            color: Colors.black,
          ),
          loadingBuilder: (context, event) => Center(
            child: CircularProgressIndicator(
              value: event == null
                  ? 0
                  : event.cumulativeBytesLoaded / (event.expectedTotalBytes ?? 1),
            ),
          ),
        ),
      ),
    );
  }
}